/*
 * @Description: 
 * @Author: Yong
 * @Date: 2021-10-02 10:47:47
 * @LastEditTime: 2021-10-02 13:25:07
 */
import * as jwt from 'jsonwebtoken'

class JWT {
    private CERT = 'I AM CERT'
    
    // 生成TOKEN
    generateToken (data: any): string {
        const EXP_TIME = Math.floor(Date.now() / 1000) + 60 * 30
        return jwt.sign({ data, exp: EXP_TIME  }, this.CERT)
    }

    // 校验TOKEN
    verifyToken (Token) {
        let res = null
        try {
            res = jwt.verify(Token, this.CERT)
        } catch (e) {
            res = 'err'
        }
        return res
    }
    
}

export const verify = new JWT